Skip to content

feature: graphical visualizations for circuits#1239

Open
skushagra wants to merge 12 commits into
amazon-braket:mainfrom
skushagra:feat/graphical-circuits
Open

feature: graphical visualizations for circuits#1239
skushagra wants to merge 12 commits into
amazon-braket:mainfrom
skushagra:feat/graphical-circuits

Conversation

@skushagra
Copy link
Copy Markdown

Issue #1083

Description of changes:

  • Added show() method and import of MatplotlibCircuitDiagram
  • Abstract base class that computes a CircuitLayout from a circuit.
  • Concrete renderer that draws the layout as a matplotlib Figure
  • added test_matplotlib_circuit_diagram.py

Testing done: Yes

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have checked that my tests are not configured for a specific region or account (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@skushagra skushagra requested a review from a team as a code owner April 5, 2026 12:34
@skushagra
Copy link
Copy Markdown
Author

skushagra commented Apr 5, 2026

Points to note

  1. Currently I have not added a circuit break. So after what depth the circuit should break into different lines.
    ... will add more as required

Question

  1. After what depth the circuit should break?
  2. What should color scheme of the Figure generated?
    ... will add more as required

@skushagra
Copy link
Copy Markdown
Author

@rmshaffer can you guide me a little here. How can we proceed and define a timeline for review and any changes required.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (d2e3fa5) to head (d384772).

Additional details and impacted files
@@            Coverage Diff             @@
##              main     #1239    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          169       173     +4     
  Lines        10961     11373   +412     
  Branches      1412      1472    +60     
==========================================
+ Hits         10961     11373   +412     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rmshaffer
Copy link
Copy Markdown
Contributor

@skushagra could you share some images of the visualizations generated by your changes? (alternatively you could add a python script to /examples which generates some representative plots, which would make it easier to test it quickly locally)

for color scheme, I imagine defaulting to just black diagram on a white background would make sense at first. Eventually we could provide the user ways to customize this, although that's not a requirement.

@skushagra
Copy link
Copy Markdown
Author

Hello, sorry for the delay. Was very busy over the last one month. Will pick this over the coming weekend and fix all issues pending here.

Thanks

@yitchen-tim
Copy link
Copy Markdown
Contributor

Hi @skushagra thank you for the contribution! The visualization looks really great. I am trying to iterate on top of your changes and will let you know when we have a further request.

Copy link
Copy Markdown
Contributor

@sesmart sesmart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally this looks awesome :) I would just advocate for tighter spacing throughout, or easier controls for this.

"A larger example showing how the renderer scales across many moments. This is a standard Quantum Fourier Transform on 5 qubits: Hadamards interleaved with controlled phase rotations, followed by bit-reversal swaps."
]
},
{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this cell you can specify os.environ["BRAKET_DIAGRAM_WIDTH"]=135, which is more appropriate for Jupyter notebooks.

"- Controls render as filled dots, anti-controls as open dots\n",
"- Multi-qubit gates draw a vertical connection line between their qubits\n",
"- SWAP renders as an `x` on each qubit, joined by a vertical line\n",
"- Barriers render as dashed vertical lines\n",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the line between for Barrier? I actually think it's going to make it really hard when the barrier doesn't span intermediate qubits.

"source": [
"## 6. Verbatim boxes\n",
"\n",
"A verbatim box marks a subcircuit that the compiler must execute exactly as written, without optimization or rewriting. In the diagram, `StartVerbatim` and `EndVerbatim` render as labelled columns that bracket the protected region, connected by a vertical line across every qubit."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make verbatim not a gate-like box? I think it is more clear generally as an instruction. Also for space I think we should come up with a shorthand, but I would do that for the Text diagram as well.

@skushagra
Copy link
Copy Markdown
Author

@yitchen-tim Thanks. I'll stay active on updates on this PR. Thanks. Let me know in case anyhting is required.

@skushagra
Copy link
Copy Markdown
Author

@yitchen-tim Should I pick the reviewed changes or are you working on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants